<template>
    <div style="display:flex;line-height:60px;">
        <div>
            <i class="el-icon-s-fold" style="font-size:30px;"></i>
        </div>
        <div style="flex:1;text-align:center;font-size:2px;">
        </div>
        <el-dropdown>
            <span>{{user.name}}</span>
            <i class="el-icon-arrow-down" style="margin-left: 5px"></i>
            <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
            <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        
    </div>
</template>

<script>
export default {
  name: 'Header',
  data(){
      return{
          user: JSON.parse(localStorage.getItem('CurUser'))
      }
  },

  props:{
      icon:String
  },

  methods:{
      logout(){
        //   console.log(123)
          this.$router.push("/login")
          localStorage.clear()

      },
      toUser(){
          console.log(123)
          this.$router.push("/home")
      }
      
  },
  created(){
          if (!localStorage.getItem("token")){
              this.$router.replace('/login');
          }else {
              // this.$router.push("/Home")
          }
      }
  
}
</script>


<style scoped>

</style>
